﻿@using OA.Models;
@model OA.Models.MenuItem
@{
    var options = new AjaxOptions
    {
        OnBegin = "ajaxBegin",
        OnSuccess = "ajaxSuccess"
    };
}

@using (Ajax.BeginForm("Update", "MenuItem", options, new { @class = "w-form" }))
{
    @Html.HiddenFor(d => d.Id)
    <div class="w-content">
        <div class="form-table">
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Name)
                </div>
                <div class="form-td">
                    @Html.Kendo().TextBoxFor(d => d.Name)
                </div>
            </div>
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Sort)
                </div>
                <div class="form-td">
                    @Html.Kendo().TextBoxFor(d => d.Sort)
                </div>
            </div>
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.Route)
                </div>
                <div class="form-td">
                    @Html.Kendo().TextBoxFor(d => d.Route)
                </div>
            </div>
            <div class="form-tr">
                <div class="form-td">
                    @Html.DisplayNameFor(d => d.MenuId)
                </div>
                <div class="form-td">
                    @(
                        Html.Kendo().DropDownListFor(model => model.MenuId)
                        .DataTextField("Name")
                        .DataValueField("Id")
                        .DataSource(source => {
                            source.Read(read => {
                                read.Action("Read", "Menu");
                            });
                        })
                    )
                </div>
            </div>
        </div>
    </div>
    <div class="w-footer">
        @(
            Html.Kendo().Button()
            .Name("Cancel")
            .Events(e => e.Click("closeWindow"))
            .HtmlAttributes(new { type = "button" })
            .Icon("cancel")
            .Content("取消")
        )
        @(
            Html.Kendo().Button()
            .Name("Enter")
            .Icon("check")
            .Content("更新")
            .HtmlAttributes(new { @class = "k-primary" })
        )
    </div>
}

<script>
    function ajaxBegin() {
        openLoading();
    }
    function ajaxSuccess(response) {
        if (response.IsSuccess) {
            $("#grid").data("kendoGrid").dataSource.read();
            closeWindow();
            openNotification(response.Message, "success");
        }
        else {
            openNotification(response.Message, "error");
        }
        closeLoading();
    }
</script>
